package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.annotation.RequiresPermissionsDesc;
import com.qf.pojo.DtsAddress;
import com.qf.service.AddressService;
import com.qf.util.ResponseUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/admin/address")
public class AddressController {

    @Autowired
    private AddressService addressService;


    //http://localhost:8080/admin/address/list?
    //page=1&limit=20&name=asdf&userId=1&sort=add_time&order=desc
    @RequiresPermissions("admin:address:list")
    @RequiresPermissionsDesc(menu = {"用户管理","收获地址"},button = "查询")
    @GetMapping("/list")
    public Object list(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "20") Integer limit,
                       String name,Integer userId,String sort,String order) {

        IPage<DtsAddress> iPage = addressService.findListByQuery(page,limit,name,userId,sort,order);

        Map data=new HashMap();
        data.put("total",iPage.getTotal());
        data.put("items",iPage.getRecords());
        return ResponseUtil.ok(data);
    }


}
